package services

import (
	"dims/entity"
	"fmt"
	"time"
)

func (s *Service) {{.ClassName}}QueryPage(req *entity.{{.ClassName}}PageReq) (list []*entity.{{.ClassName}}, count int64, err error) {
	list, count, err = s.dataSource.{{.ClassName}}QueryPage(req)
	if err != nil {
		return nil, 0, err
	}
	return
}

func (s *Service) {{.ClassName}}LoadById(id int64) entity.{{.ClassName}} {
	result := entity.{{.ClassName}}{}
	s.dataSource.DB.First(&result, id)
	return result
}

func (s *Service) {{.ClassName}}Delete(id int64) (err error) {
    // 可以自定义判断

	s.dataSource.DB.Delete(&entity.{{.ClassName}}{}, id)
	return
}

func (s *Service) {{.ClassName}}Save(req entity.{{.ClassName}}) (id int64, err error) {
	if req.Id == 0 {
	    // 可以自定义判断

		req.CreateTime = utils.JsonTime{Time: time.Now()}
		req.UpdateTime = utils.JsonTime{Time: time.Now()}
		s.dataSource.DB.Create(&req)
		id = req.Id
	}
	return
}

func (s *Service) {{.ClassName}}Update(req entity.{{.ClassName}}) (id int64, err error) {

    if req.Id > 0 {
        // 可以自定义判断

		req.UpdateTime = utils.JsonTime{Time: time.Now()}
        s.dataSource.DB.Updates(&req)
        id = req.Id
    }
    return
}